import { useDispatch, useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import withLogin from '../../components/withLogin'

export const My = () => {
	const user = useSelector((state: any) => state.user)
	const dispatch = useDispatch()
	const navigate = useNavigate()
	const handleQuit = () => {
		localStorage.removeItem('token')
		dispatch({ type: 'SET_USER', payload: '' })
		navigate({ pathname: '/login' })
	}
	return (
		<>
			<h1>当前用户：{user}</h1>
			<button onClick={() => handleQuit() }>退出登录</button>
		</>
	)
}

export default withLogin(My)